import 'dart:convert';

class ToolImage {
  String id;
  String toolName;
  String toolSpec;
  String toolUrl;
  ToolImage({
    required this.id,
    required this.toolName,
    required this.toolSpec,
    required this.toolUrl,
  });

  ToolImage copyWith({
    String? id,
    String? toolName,
    String? toolSpec,
    String? toolUrl,
  }) {
    return ToolImage(
      id: id ?? this.id,
      toolName: toolName ?? this.toolName,
      toolSpec: toolSpec ?? this.toolSpec,
      toolUrl: toolUrl ?? this.toolUrl,
    );
  }

  Map<String, dynamic> toMap() {
    final result = <String, dynamic>{};
  
    result.addAll({'id': id});
    result.addAll({'toolName': toolName});
    result.addAll({'toolSpec': toolSpec});
    result.addAll({'toolUrl': toolUrl});
  
    return result;
  }

  factory ToolImage.fromMap(Map<String, dynamic> map) {
    return ToolImage(
      id: map['id'] ?? '',
      toolName: map['toolName'] ?? '',
      toolSpec: map['toolSpec'] ?? '',
      toolUrl: map['toolUrl'] ?? '',
    );
  }

  String toJson() => json.encode(toMap());

  factory ToolImage.fromJson(String source) => ToolImage.fromMap(json.decode(source));

  @override
  String toString() {
    return 'ToolImage(id: $id, toolName: $toolName, toolSpec: $toolSpec, toolUrl: $toolUrl)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
  
    return other is ToolImage &&
      other.id == id &&
      other.toolName == toolName &&
      other.toolSpec == toolSpec &&
      other.toolUrl == toolUrl;
  }

  @override
  int get hashCode {
    return id.hashCode ^
      toolName.hashCode ^
      toolSpec.hashCode ^
      toolUrl.hashCode;
  }
}
